package com.example.aircraft;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.aircraft.aircraft.BossEnemy;
import com.example.aircraft.aircraft.EliteEnemy;
import com.example.aircraft.aircraft.HeroAircraft;
import com.example.aircraft.aircraft.MobEnemy;
import com.example.aircraft.bullet.EnemyBullet;
import com.example.aircraft.bullet.HeroBullet;
import com.example.aircraft.prop.Prop_Blood;
import com.example.aircraft.prop.Prop_Bomb;
import com.example.aircraft.prop.Prop_Bullet;
import com.example.aircraft.prop.Prop_Redtea;

import java.util.HashMap;

import java.util.Map;


/**
 * 综合管理图片的加载，访问
 * 提供图片的静态访问方法
 *
 * @author lzf&cs
 */
public class ImageManager {

    /**
     * 类名-图片 映射，存储各基类的图片 <br>
     * 可使用 CLASSNAME_IMAGE_MAP.get( obj.getClass().getName() ) 获得 obj 所属基类对应的图片
     */
    private static final Map<String, Bitmap> CLASSNAME_IMAGE_MAP = new HashMap<>();
    public static Bitmap BACKGROUND1_IMAGE;
    public static Bitmap BACKGROUND2_IMAGE;
    public static Bitmap BACKGROUND3_IMAGE;
    public static Bitmap BACKGROUND4_IMAGE;
    public static Bitmap BACKGROUND5_IMAGE;
    public static Bitmap HERO_IMAGE;
    public static Bitmap HERO_BULLET_IMAGE;
    public static Bitmap ENEMY_BULLET_IMAGE;
    public static Bitmap MOB_ENEMY_IMAGE;
    public static Bitmap ELITE_ENEMY_IMAGE;
    public static Bitmap BOSS_ENEMY_IMAGE;
    public static Bitmap PROP_BLOOD_IMAGE;
    public static Bitmap PROP_BOMB_IMAGE;
    public static Bitmap PROP_BULLET_IMAGE;
    public static Bitmap PROP_REDTEA_IMAGE;

    static {

            BACKGROUND1_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bg1);
            BACKGROUND2_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bg2);
            BACKGROUND3_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bg3);
            BACKGROUND4_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bg4);
            BACKGROUND5_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bg5);
            HERO_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.hero);
            HERO_BULLET_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bullet_hero);
            ENEMY_BULLET_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.bullet_enemy);
            MOB_ENEMY_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.mob);
            ELITE_ENEMY_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.elite);
            BOSS_ENEMY_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.boss);
            PROP_BLOOD_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.prop_blood);
            PROP_BOMB_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.prop_bomb);
            PROP_BULLET_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.prop_bullet);
            PROP_REDTEA_IMAGE = BitmapFactory.decodeResource(MyApplication.getContext().getResources(),R.drawable.redtea);



            CLASSNAME_IMAGE_MAP.put(HeroAircraft.class.getName(), HERO_IMAGE);
            CLASSNAME_IMAGE_MAP.put(MobEnemy.class.getName(), MOB_ENEMY_IMAGE);
            CLASSNAME_IMAGE_MAP.put(EliteEnemy.class.getName(), ELITE_ENEMY_IMAGE);
            CLASSNAME_IMAGE_MAP.put(BossEnemy.class.getName(), BOSS_ENEMY_IMAGE);
            CLASSNAME_IMAGE_MAP.put(HeroBullet.class.getName(), HERO_BULLET_IMAGE);
            CLASSNAME_IMAGE_MAP.put(EnemyBullet.class.getName(), ENEMY_BULLET_IMAGE);
            CLASSNAME_IMAGE_MAP.put(Prop_Blood.class.getName(), PROP_BLOOD_IMAGE);
            CLASSNAME_IMAGE_MAP.put(Prop_Bomb.class.getName(), PROP_BOMB_IMAGE);
            CLASSNAME_IMAGE_MAP.put(Prop_Bullet.class.getName(), PROP_BULLET_IMAGE);
            CLASSNAME_IMAGE_MAP.put(Prop_Redtea.class.getName(), PROP_REDTEA_IMAGE);


    }

    public static Bitmap get(String className){
        return CLASSNAME_IMAGE_MAP.get(className);
    }

    public static Bitmap get(Object obj){
        if (obj == null){
            return null;
        }
        return get(obj.getClass().getName());
    }

}
